package logic

import (
	"context"
	"fmt"
	"srv/model/redis"

	"srv/cart"
	"srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AmountCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAmountCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AmountCartLogic {
	return &AmountCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AmountCartLogic) AmountCart(in *cart.AmountCartRequest) (*cart.AmountCartResponse, error) {
	// todo: add your logic here and delete this line
	amountCart, err := redis.AmountCart(in.UserId)
	if err != nil {
		logx.Error("总价钱获取失败")
		return nil, fmt.Errorf("总价钱获取失败")
	}
	return &cart.AmountCartResponse{Amount: uint64(amountCart)}, nil
}
